package com.hezuti.sns.dao;


import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Property;
import org.springframework.stereotype.Component;

import com.hezuti.common.dao.BaseHibernateDaoGeneric;
import com.hezuti.sns.domain.Lserial;

/**
 * 记录用户登录信息
 * 
 * @author Administrator
 *
 */
@Component
public class LserialDao extends  BaseHibernateDaoGeneric<Lserial>{
	
	/**
	 * 
	 * @param uid
	 * @param ip
	 * @param loginType
	 */
	public void addRec(int uid,String ip,int loginType){
		Lserial l=new Lserial();
		l.setUid(uid);
		l.setIp(ip);
		l.setLogin_type(loginType);
		l.setLogin_time(new Date());
		this.save(l);
	}
	
	/**
	 * 上次登录信息，<br/>
	 * Lserial OR null
	 * @param uid
	 * @return
	 */
	public Lserial getLastLoginInfo(int uid){
		Criteria c = this.createCriteria(Lserial.FIELD_LOGIN_TIME,false,Property.forName(Lserial.FIELD_UID).eq(uid)).setMaxResults(1);
		return this.findUniqueBy(c);
	}
}
